<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript">
    $(function () {
        var mode = document.getElementById("edit_mode").value;

        if (mode == 5) {
            $('#editCall').hide();
            $('#userAccept').hide();
            $('#editComplete').show();
        } else {
            $('#editCall').show();
            $('#userAccept').show();
            $('#editComplete').hide();
        }


    });

    function validateObjection() {
        $('#objectionId').rules("add", {
            isObjection: true,
            messages: {
                ageValidate: $('#pls_enter_valid_OBJ').val()}
        });
    }

    function validateNoObjection() {
        var obj = $('#objectionId').val();
        if (obj.length > 0) {
            $('#noObjectionBtnId').hide();
        } else {
            $('#noObjectionBtnId').show();
        }
    }

    function validateRejection(elementId) {
        // $('#rejectComment').show()
        var comment_on_rejection = $('#pls_enter_comment_on_rejection').val();

        //alert($('#' +elementId).val());

        $('#' + elementId).rules("add", {
            required: true,
            messages: {
                required: comment_on_rejection }
        });
    }

</script>


<table class="width-100">
    <s:hidden id="edit_mode" name="editMode"/>
    <s:hidden name="landApplication.workflowItem.workflowTask"/>
    <s:hidden name="landApplication.workflowItem.id"/>
    <s:hidden name="applicationId"/>
    <s:hidden name="landApplication.id"/>
    <s:hidden name="contacts.id"/>
    <s:hidden name="landApplication.initApplicationId"/>
    <s:hidden name="contactPerson.id"/>
    <s:hidden name="holder.id"/>
    <s:hidden id="state" value="%{getText('state.label')}"/>
    <s:hidden name="initApplicationId"/>
    <s:hidden name="landApplication.version"/>


    <s:if test="landApplication.workflowItem != null">
        <tr>
            <td><s:label value="%{getText('status.label')}"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>
                <s:label name="landApplication.workflowItem.workflowTask.action"/>
            </td>
        </tr>
    </s:if>

    <s:if test="slcObjections != null && slcObjections.length() >0">
        <tr>
            <td>
                <s:label value="%{getText('public_objections_history.label')}"/>
            </td>
            <td><s:textarea id="viewObjectionSlc" name="slcObjections"
                            cssClass="width-595-px" readonly="true"/></td>

        </tr>
    </s:if>

    <s:if test="landApplication.objections.length() >0">
        <tr>
            <td>
                <s:label value="%{getText('objections_history.label')}"/>
            </td>
            <td><s:textarea id="viewObjection" name="landApplication.objections"
                            cssClass="width-595-px" readonly="true"/></td>

        </tr>
    </s:if>

    <%--enable objections--%>
    <s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_DATA_ENTRY ||
    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@INTERVIEW_COMPLETED">
        <tr>
            <td>
                <s:label value="%{getText('objections.label')}"/>
            </td>

            <s:if test="objectionDisabled">
                <td><s:div id="message-box" class="message-box">
                    <div class="action-msg">Objection Accepting Time Period Has Expired</div>
                </s:div><%--
                <s:textarea id="objectionId" name="objections"
                            cssClass="width-595-px" readonly="true"/> --%></td>
                <script type="text/javascript">
                    $(function () {
                        $('#gov-land-init-permit-application-form_handleObjections').hide();
                    });
                </script>
            </s:if>
            <s:else>
                <td><s:textarea id="objectionId" name="objections" onkeyup="validateNoObjection()"
                                cssClass="width-595-px"/></td>
            </s:else>
                <%--
              <td><s:textarea id="objectionId" name="objections" onkeyup="validateNoObjection()"
                              cssClass="width-595-px"/></td>  --%>
        </tr>
    </s:if>
    <%--display comments history--%>
    <s:if test="landApplication.comment.length() >0">
        <tr>
            <td>
                <s:label value="%{getText('comments_history.label')}"/>
            </td>
            <td><s:textarea id="commentId" name="landApplication.comment"
                            cssClass="width-595-px" readonly="true"/></td>
        </tr>
    </s:if>

    <%--enable comments input--%>
    <s:if test="#session.userGroup=='ords' || #session.userGroup=='plc' || #session.userGroup=='lcg' || #session.userGroup=='orlp' ||
                #session.userGroup=='ma' || #session.userGroup=='alc' || #session.userGroup=='lc' || #session.userGroup=='pma' || #session.userGroup=='aplc' || #session.userGroup=='dplc' ||
                || #session.userGroup=='orip'">
        <tr>
            <td>
                <s:label value="%{getText('comment.label')}"/>
            </td>
            <td><s:textarea id="viewcommentId" name="comment"
                            cssClass="width-595-px"/></td>
        </tr>
    </s:if>

</table>

<%-- Except Grant Application --%>
<%--<s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_FINALIZED && alienationType!=2">
    <s:include value="attachLand.jsp"/>
</s:if>--%>


<s:if test="searchValue !=1">
<%--display land list--%>
<s:if test="alienationType!=2">
    <s:include value="../../landTree.jsp"/>
</s:if>

<%--<div>
    <s:if test="#session.userGroup =='lo'">
        <s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@APPROVED">
            <s:include value="../AttachedAlienationDoc.jsp"/>
        </s:if>
    </s:if>
</div>--%>


<div class="form-button-div right-align">
    <%--short listed candidate login and input/update detailed app --%>
<s:if test="#session.userGroup =='slc'">
    <%--<s:if test="editMode==0">--%>
    <%--<s:hidden name="editMode" value="0"/>--%>

    <%--add detailed application by slc--%>
    <s:if test="landApplication.initApplicationId==0">
        <s:submit value="%{getText('save.label')}" action="addInitLandApplicationByApplicant"/>
    </s:if>
    <%--</s:if>--%>
    <%--<s:elseif test="editMode==1">--%>
    <%--<s:hidden name="editMode" value="1"/>--%>

    <%--edit detailed application by slc--%>
    <s:else>
        <s:submit value="%{getText('update.label')}" action="addInitLandApplicationByApplicant"/>
    </s:else>
    <%--</s:elseif>--%>
</s:if>

<s:elseif test="#session.userGroup =='lo' || #session.userGroup =='orlm' || #session.userGroup =='orip'">
    <%--input detail information on initial app--%>
    <s:if test="landApplication.initApplicationId==0">
        <s:submit value="%{getText('save.label')}" action="addInitLandApplication"/>
        <s:submit value="%{getText('cancel.label')}" action="approvedInitApplicationFormsList"/>
        <%--</s:if>--%>
    </s:if>
    <%-- detailed app--%>
    <s:else>
        <%--modify detailed app--%>
        <s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_DATA_ENTRY">
            <%--<s:hidden name="editMode" value="1"/>--%>
            <s:submit value="%{getText('update.label')}" action="addInitLandApplication"/>
            <s:submit value="%{getText('cancel.label')}" action="detailApplicationToBeEdit"/>

        </s:if>

        <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_REJECTED">
            <%--<s:hidden name="editMode" value="1"/>--%>
            <s:submit value="%{getText('update.label')}" action="addInitLandApplication"/>
            <s:submit value="%{getText('cancel.label')}" action="detailApplicationToBeEdit"/>

        </s:elseif>

        <%--conducting interview by lo--%>
        <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_APPROVED ||
                landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@INTERVIEW_DATA_ENTRY">
            <%--<s:hidden name="editMode" value="4"/>--%>
            <s:submit value="%{getText('update.label')}" action="addInitLandApplication"/>
            <s:submit value="%{getText('update_and_complete_button.label')}" action="completeInterviews"/>
            <%--<s:submit value="%{getText('cancel.label')}" action="interviewAppListPageLoad"/>--%>

        </s:elseif>
        <%--No objection by lo --%>
        <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@INTERVIEW_COMPLETED">

            <s:submit value="%{getText('update.label')}" action="handleObjections" onclick="validateObjection()"/>
            <%--  <s:submit value="Send Objections to PLC"
            action="completeObjectionHandling"/>--%>
            <s:submit id="noObjectionBtnId" value="%{getText('no_objections.label')}" action="noObjections"/>
        </s:elseif>

        <%--objection data entry by lo --%>
        <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_DATA_ENTRY">

            <s:submit value="%{getText('update.label')}" action="handleObjections" onclick="validateObjection()"/>
            <%--  <s:submit value="Send Objections to PLC"
            action="completeObjectionHandling"/>--%>
            <%-- <s:submit value="No Objections" action="noObjections"/>--%>
        </s:elseif>

        <%--attach land--%>
        <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_FINALIZED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@LAND_ALLOCATION_REJECTED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@LAND_ALLOCATED">
            <s:include value="attachLand.jsp"/>
            <s:submit value="%{getText('save_and_recommend.label')}" action="attachLandToApplication"/>
            <%--<s:submit value="%{getText('cancel.label')}" action="detailApplicationFinalized"/>--%>

        </s:elseif>

        <%--complete application--%>
        <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@LAND_ALLOCATION_APPROVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED_AND_ARCHIVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@NOT_SUBMITTED_AND_ARCHIVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED_APPLICATION_REJECTED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECT_REJECTED_AND_ARCHIVED_APPLICATION ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECT_NOT_SUBMITTED_APPLICATION ">

            <table>
                <tr>
                    <td>
                        <s:label value="%{getText('lo_comments.label')}"/>
                    </td>
                    <td><s:textarea id="loCommentId" name="comment"
                                    cssClass="width-595-px"/>
                    </td>
                </tr>

            </table>
            </br>
            <table id="userAccept">
                <tr>
                    <td colspan="2">
                        <s:label value="%{getText('applicant_agreeto_accept_land.label')}"/>
                    </td>
                </tr>
                <tr colspan="2">
                    <td><%--<s:submit value="%{getText('agree.label')}" action="addInitLandApplication"/>--%>
                        <s:submit value="%{getText('agree.label')}" action="acceptAndCompleteApplication"/>
                    </td>

                    <td><s:submit value="%{getText('disagree.label')}" action="rejectAndCompleteApplication"/>
                    </td>

                    <td><%--<s:submit value="%{getText('not_responded.label')}"
                                  action="notSubmittedAndCompleteApplication"/>--%>
                        <s:if test="landApplication.letterCount == 0 ">
                            <s:submit value="%{getText('generate_letter.label')}"
                                      action="generateLetterForApplication"/>
                        </s:if>
                        <s:elseif test="landApplication.letterCount == 1 ">
                            <s:submit value="%{getText('generate_letter.label')}"
                                      action="generateLetterForApplication"/>
                        </s:elseif>
                        <s:else>
                            <s:submit value="%{getText('not_responded.label')}"
                                      action="notSubmittedAndCompleteApplication"/>
                        </s:else>

                    </td>
                </tr>

            </table>

            <br>
            <table id="editCall">
                <tr>
                    <td colspan="3">
                        <s:label value="%{getText('applicant_details_need_to_change.label')}"/>
                    </td>
                    <td></td>
                    <td></td>
                    <td><s:submit value="%{getText('yes.label')}" action="editCompleteApplication"/></td>
                </tr>
            </table>
            <table id="editComplete">
                <tr>
                    <td><s:submit value="%{getText('edit.label')}" action="addInitLandApplication"/></td>
                </tr>
            </table>

            <%--<s:submit value="%{getText('cancel.label')}" action="loadApplicationToComplete"/>--%>

        </s:elseif>

        <%-- <s:elseif
                            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED_APPLICATION_APPROVED ||
                            landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@APPROVED">
                        &lt;%&ndash;<s:include value="../AttachedAlienationDoc.jsp"/>&ndash;%&gt;

                        <s:submit value="%{getText('save.label')}" action="saveAttachedAlienationDoc"/>
                        <s:submit value="%{getText('cancel.label')}" action="initApplicationAgreement"/>
                    </s:elseif>
        --%>
    </s:else>
</s:elseif>

<s:elseif test="#session.userGroup =='ords'">
    <%--only for ds--%>
    <s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_DATA_ENTRY">
        <s:submit value="%{getText('approve.label')}" action="approveDetailedApplication"/>
        <s:submit value="%{getText('reject_button.label')}" action="rejectDetailedApplication"
                  onclick="javascript:return validateRejection('viewcommentId')"/>
        <s:submit value="%{getText('cancel.label')}" action="loadDetailedApplicationListToBeApproved"/>
    </s:if>

    <%--finalize by ords--%>
    <s:elseif
            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_HANDLING_APPROVED ||
                landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_HANDLING_COMPLETED">
        <%--<s:hidden name="editMode" value="7"/>--%>
        <s:submit value="%{getText('finalize_button.label')}" action="finalizeApplication"/>
        <s:submit value="%{getText('cancel.label')}" action="appListToBeFinalizedPageLoad"/>

    </s:elseif>

    <%--attach land approval--%>
    <s:elseif
            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@LAND_ALLOCATED">

        <%--<s:submit value="%{getText('approve_allocation_button.label')}" action="approveLandAllocation"/>
        <s:submit value="%{getText('reject_allocation_button.label')}" action="rejectLandAllocation"
                  onclick="javascript:return validateRejection('viewcommentId')"/>--%>


        <s:submit value="%{getText('approve.label')}" action="approveLandAllocationWithByPass"/>
        <s:submit value="%{getText('reject_allocation_button.label')}" action="rejectLandAllocation"
                  onclick="javascript:return validateRejection('viewcommentId')"/>
        <%--<s:submit value="%{getText('reject.label')}" action="rejectCompletedApplicationByDS"
                  onclick="javascript:return validateRejection('viewcommentId')"/>--%>

        <s:submit value="%{getText('cancel.label')}" action="home"/>

    </s:elseif>

    <%--approve completed app--%>
    <%--<s:elseif
            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED">
        <s:submit value="%{getText('approve.label')}" action="approveCompletedApplication"/>
        <s:submit value="%{getText('reject.label')}" action="rejectCompletedApplicationByDS"/>
        <s:submit value="%{getText('cancel.label')}" action="home"/>

    </s:elseif>

    <s:elseif
            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED_AND_ARCHIVED">
        <s:submit value="%{getText('approve.label')}" action="approveCompletedApplication"/>
        <s:submit value="%{getText('reject.label')}" action="rejectCompletedApplicationByDS"/>
        <s:submit value="%{getText('cancel.label')}" action="home"/>

    </s:elseif>--%>

    <s:elseif
            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED ||
            landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED_AND_ARCHIVED ||
            landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@NOT_SUBMITTED_AND_ARCHIVED ||
            landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED ">
        <s:submit value="%{getText('approve.label')}" action="approveCompletedApplication"/>
        <s:submit value="%{getText('reject.label')}" action="rejectCompletedApplicationByDS"
                  onclick="javascript:return validateRejection('viewcommentId')"/>
        <s:submit value="%{getText('cancel.label')}" action="home"/>

    </s:elseif>

    <%--approve signed documents--%>

    <%--  <s:elseif
                    test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@SIGNED_PRINTED_ALIENATION_DOCUMENT">
                <s:include value="../AttachedAlienationDoc.jsp"/>
                <s:submit value="%{getText('approve.label')}" action="approveSignDocApplication"/>
                <s:submit value="%{getText('reject_button.label')}" action="rejectAttachedAlienationDoc"/>
                <s:submit value="%{getText('cancel.label')}" action="home"/>

            </s:elseif>
    --%>
</s:elseif>

<s:elseif test="#session.userGroup =='plc'">
    <%--approve objection by PLC--%>
    <s:if
            test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_DATA_ENTRY">

        <%--<s:hidden name="editMode" value="6"/>--%>
        <s:submit value="%{getText('approve.label')}" action="approveObjections"/>
        <s:submit value="%{getText('update.label')}" action="handleObjections"/>

    </s:if>
</s:elseif>
<s:if test="#session.userGroup =='orip'">
    <s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@DETAILED_FORM_DATA_ENTRY">
        <s:submit value="%{getText('approve.label')}" action="approveDetailedApplication"/>
        <s:submit value="%{getText('reject_button.label')}" action="rejectDetailedApplication"
                  onclick="javascript:return validateRejection('viewcommentId')"/>

    </s:if>

    <s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_DATA_ENTRY">

        <%--<s:hidden name="editMode" value="6"/>--%>
        <s:submit value="%{getText('approve.label')}" action="approveObjections"/>
        <s:submit value="%{getText('update.label')}" action="handleObjections"/>

    </s:if>

    <s:elseif
                test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_HANDLING_APPROVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@OBJECTION_HANDLING_COMPLETED">
            <%--<s:hidden name="editMode" value="7"/>--%>
            <s:submit value="%{getText('finalize_button.label')}" action="finalizeApplication"/>
            <s:submit value="%{getText('cancel.label')}" action="appListToBeFinalizedPageLoad"/>

        </s:elseif>

    <s:if
               test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@LAND_ALLOCATED">

           <%--<s:submit value="%{getText('approve_allocation_button.label')}" action="approveLandAllocation"/>
           <s:submit value="%{getText('reject_allocation_button.label')}" action="rejectLandAllocation"
                     onclick="javascript:return validateRejection('viewcommentId')"/>--%>


           <s:submit value="%{getText('approve.label')}" action="approveLandAllocationWithByPass"/>
           <s:submit value="%{getText('reject_allocation_button.label')}" action="rejectLandAllocation"
                     onclick="javascript:return validateRejection('viewcommentId')"/>
           <%--<s:submit value="%{getText('reject.label')}" action="rejectCompletedApplicationByDS"
                     onclick="javascript:return validateRejection('viewcommentId')"/>--%>

           <s:submit value="%{getText('cancel.label')}" action="home"/>

       </s:if>

</s:if>

<s:if test="#session.userGroup =='plc' || #session.userGroup =='lcg' || #session.userGroup =='orlp'">

    <%-- <s:if
             test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED_APPLICATION_APPROVED ||
             landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@APPROVED ||
             landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED ">
         <s:submit value="%{getText('approve.label')}" action="approveApplication"/>
         <s:submit value="%{getText('reject_button.label')}" action="rejectApplication"
                   onclick="javascript:return validateRejection('viewcommentId')"/>
         <s:submit value="%{getText('cancel.label')}" action="home"/>

     </s:if>--%>
</s:if>

<s:if test="landApplication.nextAction == 1">
    <s:if test="#session.userGroup =='lc'">
        <s:submit value="%{getText('approve.label')}" action="approveApplicationByLC"/>  <%-- for LC --%>
        <s:submit value="%{getText('recommend.label')}" action="recommendApplicationByLC"/>
    </s:if>
    <s:else>
        <s:submit value="%{getText('recommend.label')}" action="approveApplication"/>
    </s:else>
    <s:submit value="%{getText('reject_button.label')}" action="rejectApplication"
              onclick="javascript:return validateRejection('viewcommentId')"/>
</s:if>

<s:if test="landApplication.nextAction == 2">
    <s:submit value="%{getText('recommend.label')}" action="approveApplication"/>
</s:if>

    <%--<s:elseif test="landApplication.nextAction == 2">
        <s:submit value="%{getText('recommend.label')}" action="approveApplication"/>
        <s:submit value="%{getText('reject_button.label')}" action="rejectApplication" onclick="javascript:return validateRejection('viewcommentId')"/>
        <s:submit value="%{getText('cancel.label')}" action="home"/>
    </s:elseif>--%>

    <%--workflow--%>
</div>
</s:if>
<s:else>
    <s:if test="alienationType!=2">
        <s:include value="../../landTree.jsp"/>
    </s:if>
</s:else>

<s:hidden id="pls_enter_comment_on_rejection" value="%{getText('pls_enter_comment_on_rejection.label')}"/>
